﻿using System;
using DNT.RavenQA.Core.Models;
using Raven.Client;

namespace DNT.RavenQA.Web.Infrastructure.Commands
{
    public class AddQuestionCommand : RavenCommand<IQuestionInput, CommandResult<Int32>>
    {
        private readonly IQuestionInput _parameter;

        public AddQuestionCommand(IQuestionInput parameter)
            : base(parameter)
        {
            _parameter = parameter;
        }

        public override CommandResult<Int32> Execute(IDocumentSession session)
        {
            var question = Question.New(_parameter);
            session.Store(question);
            return new CommandResult<Int32>(question.Key);
        }
    }
}